package ai.mspbots.poc.es.processor;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;

public class MapperProcessor {

    public static String processInput(String userInput) {
        StringBuilder processedInput = new StringBuilder();
        try (StringReader reader = new StringReader(userInput)) {
            IKSegmenter segmented = new IKSegmenter(reader, true);
            Lexeme lexeme;
            while ((lexeme = segmented.next()) != null) {
                // System.out.println("lexeme.getLexemeText() = " + lexeme.getLexemeText());
                processedInput.append(AbbreviationMapper.replaceAbbreviations(lexeme.getLexemeText())).append(" ");
            }
            String processedInputString = processedInput.toString().trim();
            // System.out.println("processedInputString = " + processedInputString);
            return processedInputString;
        } catch (IOException e) {
            e.printStackTrace();
            return userInput; // 出错时返回原始输入
        }

    }
}